package views;
/**
 * EDCTextViewer
 * Viewer to display the contents of a DTD File (Quick view without syntax highlighting)
 */
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import utils.EDCResource;
import io.FileControler;

public class EDCTextViewer extends EDCDefaultViewer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected JTextArea textArea;
    protected String newline = "\n";
    
	public EDCTextViewer(String filename) {
		
		setTitle("Text viewer");
		getContentPane().setLayout(new BorderLayout());
		//Create the text area used for output.
        textArea = new JTextArea(20, 20);
        textArea.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(textArea);
//        Dimension minimumSize = new Dimension(620, 50);
        //scrollPane.setMinimumSize(minimumSize);
        scrollPane.setPreferredSize(new Dimension(300,300));
        
//      String path = EDCResource.dtdFolderPath+File.separator+filename;
        String path = "";
        try {
        	path = EDCResource.inputFile.getCanonicalPath()+File.separator+filename;
        } catch (Exception e) {
        	e.printStackTrace();
        }
       
        String txt = FileControler.getFileContents(path);
        textArea.setText(txt);
        //start point
        textArea.setCaretPosition(0);
        
        getContentPane().add(scrollPane, BorderLayout.CENTER);
	}
	
}
